<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %> 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>用户信息</title>
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript">

   function  del(id) {
	    $.ajax({
            type: 'POST',
            url: '/del',
            data: {"id":id},
            success: function (data) {
            	var da=eval('(' + data + ')');
            	  if(da.resul==1){
            		  alert("删除成功");
            		  window.location.href='/index';
            	  }
            	  else{
            		  alert("删除失败");
            	  }
            },
            error: function () {
                alert("出错了,请重试!");
            }
        });
}
</script>
 <script type="text/javascript">
    function edit(id) {
    	if(id==''){
			window.location.href='/admin/upload/forms';
			
		}
		else {
			window.location.href='/edit?id='+id;
		
		}
	}
    </script> 
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">weirdor</a>
    </div>
   
    <ul class="nav navbar-nav navbar-right">
    
    
   <c:choose>
   <c:when test="${currentUser==null}">
     <li><a href="#"><span class="glyphicon glyphicon-user"></span> 注册</a></li>
       <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> 登录</a></li>

   </c:when>
   <c:otherwise>
    <li class="dropdown">
            <shiro:user>  
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
           <span class="glyphicon glyphicon-user"></span> <shiro:principal/><b class="caret"></b>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="/logout">退出</a></li>
                </ul>
                </shiro:user>
            </li>
   </c:otherwise>
   </c:choose>   
    </ul>
  </div>
</nav>


<div class="panel panel-default">
    <div class="panel-body">
     <div class="row">
      <shiro:hasRole name="管理员">
       <div class="col-xs-12 col-sm-8 col-md-offset-2"> 
       
      
         <div class="table-responsive">
	<table class="table">
		<thead>
			<tr>
				<th width="20%">id</th>
				<th width="20%">用户名</th>
				<th>角色</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		  <c:forEach items="${userList}" var="list" varStatus="i">
		       
			<tr>
				<th width="20%">${i.index+1 }</th>
				<td width="20%">${list.username}</td>
				<td>${list.roleName}</td>
				<td>
				<button type="button" class="btn btn-primary" onclick="edit('${list.id}');">修改</button>
				<button type="button" class="btn btn-danger" onclick="del('${list.id}');">删除</button>
				</td>
			</tr>
			    </c:forEach>
		</tbody>
</table>


</div>  	
    
      
</div>
<div class="col-xs-12 col-sm-6 col-md-offset-2">
<ul class="pager">
                             
                                    
                                       <li><a  href="/index?pageNumber=${page.current>1?page.current-1:1}">上一页</a></li>
                                            
                                            <li><a class="prev page-numbers" href="/index?pageNumber=${page.current<page.pages?page.current+1:page.pages}">下一页</a></li>
                                    
                                           
                            </ul>
</div>
  </shiro:hasRole>
  <shiro:hasRole name="普通用户">

   <div class="row">
								
								<div class="col-md-4" >
									
									<ul class='info-list' >
										
										<li>
											<strong>用户名:</strong>
											<span>${user.username}</span>
										</li>
										
										<li>
											<strong>权限:</strong>
											<span>${user.roleName}</span>
										</li>
									</ul>
									
								</div>
								<button type="button" class="btn btn-primary" onclick="edit('${user.id}');">修改</button>
								</div>

  </shiro:hasRole>
       </div>
    </div>
</div>

</body>
</html>